#########################################################################
##
## This file is part of the SAMRAI distribution.  For full copyright 
## information, see COPYRIGHT and LICENSE. 
##
## Copyright:     (c) 1997-2019 Lawrence Livermore National Security, LLC
## Description:   Test for performance and quality of mesh generation.
##
#########################################################################

SAMRAI        = @top_srcdir@
SRCDIR        = @srcdir@
SUBDIR        = source/test/performance/MeshGeneration
VPATH         = @srcdir@
OBJECT        = ../../../..
REPORT        = $(OBJECT)/report.xml
TESTLIBDIR    = $(OBJECT)/source/test/testlib
TESTLIB       = $(TESTLIBDIR)/libSAMRAI_test$(LIB_SUFFIX)

default: check

include $(OBJECT)/config/Makefile.config

NUM_TESTS = 41
CPPFLAGS_EXTRA= -DTESTING=1

TEST_NPROCS = @TEST_NPROCS@
QUOTE = \"

CXX_OBJS      = mg.o

INPUTS2D =	test_inputs/small_spread.2d.tile.input	\
		test_inputs/front.2d.caplb.input	\
		test_inputs/front.2d.localtile.input	\
		test_inputs/front.2d.tile.input	\
		test_inputs/front.2d.treelb.input	\
		test_inputs/front.2d.voucher.input	\
		test_inputs/lss.2d.caplb.input	\
		test_inputs/lss.2d.localtile.input	\
		test_inputs/lss.2d.tile.input	\
		test_inputs/lss.2d.tilevoucher.input	\
		test_inputs/lss.2d.treelb.input	\
		test_inputs/lss.2d.voucher.input	\
		test_inputs/lump.2d.treelb.input	\
		test_inputs/lump.2d.tilecascade.input	\
		test_inputs/lump.2d.voucher.input	\
		test_inputs/lump.2d.tilevoucher.input	\
		test_inputs/box_deep.2d.cascade.input


INPUTS3D =	test_inputs/spreadby10.3d.treelb.input		\
		performance_inputs/bigbox.3d.tile.input	\
		performance_inputs/single_sphere.3d.caplb.input	\
		performance_inputs/single_sphere.3d.treelb.input	\
		performance_inputs/lsphere_weak.3d.treelb.input	\
		performance_inputs/lsphere_weak.3d.localtile.input	\
		performance_inputs/front.3d.caplb.input	\
		performance_inputs/front.3d.treelb.input	\
		performance_inputs/front.3d.cascade.input	\
		performance_inputs/front.3d.tile.input	\
		performance_inputs/front.3d.localtile.input	\
		performance_inputs/domexlike.caplb.input	\
		performance_inputs/domexlike.treelb.input	\
		test_inputs/front.3d.caplb.input	\
		test_inputs/front.3d.localtile.input	\
		test_inputs/front.3d.tile.input	\
		test_inputs/front.3d.treelb.input	\
		test_inputs/lump.3d.tile.input	\
		test_inputs/lss.3d.caplb.input	\
		test_inputs/lss.3d.localtile.input	\
		test_inputs/lss.3d.tile.input	\
		test_inputs/lss.3d.tilevoucher.input	\
		test_inputs/lss.3d.voucher.input	\
		test_inputs/lss.3d.treelb.input

main:	$(CXX_OBJS) $(LIBSAMRAI) $(TESTLIB)
	(cd $(TESTLIBDIR) && $(MAKE) library) || exit 1 
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $(CXX_OBJS) $(TESTLIB) \
	$(LIBSAMRAI) $(LDLIBS) -o $@

# Prevents "No rule to make target" error.  Built in the rule for main.
$(TESTLIB):


check:
	$(MAKE) check2d
	$(MAKE) check3d

check1d:	main

check2d:	main
	@for f in $(INPUTS2D); do	\
	  for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	    echo "    <testcase classname=\"performance MeshGeneration\" name=$(QUOTE)$$f $$p procs$(QUOTE)>" >> $(REPORT); \
	    $(OBJECT)/config/serpa-run $$p ./main "$$f" | $(TEE) foo; \
	    if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT); fi; \
	    echo "    </testcase>" >> $(REPORT); \
	  done \
	done; \
	$(RM) foo

check3d:	main
	@for f in $(INPUTS3D); do	\
	  for p in `echo "$(TEST_NPROCS)" | tr "," " "`; do \
	    echo "    <testcase classname=\"performance MeshGeneration\" name=$(QUOTE)$$f $$p procs$(QUOTE)>" >> $(REPORT); \
	    $(OBJECT)/config/serpa-run $$p ./main "$$f" | $(TEE) foo; \
	    if ! grep "PASSED" foo >& /dev/null ; then echo "      <failure/>" >> $(REPORT); fi; \
	    echo "    </testcase>" >> $(REPORT); \
	  done \
	done; \
	$(RM) foo

checkcompile: main

checktest:
	$(RM) makecheck.logfile
	$(MAKE) check 2>&1 | $(TEE) makecheck.logfile
	$(OBJECT)/source/test/testtools/testcount.sh $(TEST_NPROCS) $(NUM_TESTS) 0 makecheck.logfile
	$(RM) makecheck.logfile

examples:

perf:	main

everything:
	$(MAKE) checkcompile || exit 1
	$(MAKE) checktest
	$(MAKE) examples
	$(MAKE) perf

checkclean:
	$(CLEAN_COMMON_CHECK_FILES)
	$(RM) *.timing*

clean: checkclean
	$(CLEAN_COMMON_TEST_FILES)
	$(RM) main

include $(SRCDIR)/Makefile.depend
